package com.test.springboot.jpa.service.impl;

import com.test.springboot.jpa.dao.UserDao;
import com.test.springboot.jpa.pojo.User;
import com.test.springboot.jpa.service.UserComplexService;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author thinkpad - 83start
 * @version v1.0
 * @create 2022/8/18 19:02
 * @package com.test.springboot.jpa.service.impl
 * @description Jpa 自定义复杂接口 实现类
 */

@Slf4j
@Service
public class UserComplexServiceImpl implements UserComplexService {

    @Autowired
    private UserDao userDao;

    @Override
    public Page<User> selectUserByPage(int pageCode, int pageSize, String sortName) {
        Sort sort = new Sort(Sort.Direction.ASC, sortName);
        Pageable pageable = new PageRequest(pageCode, pageSize, sort);
        return userDao.findAll(pageable);
    }

    @Override
    public List<User> selectUsersByLikePassword(String likePassword) {
        return userDao.findByLikePassword(likePassword);
    }
}
